<template>
<view>
	<view class="header">营业额</view>
	<view class="header1">
		<picker mode="date" :value="sdate" @change="bindDate" data-key="sdate" @cancel="cancel">
			<view class="uni-input weui-input">{{sdate ? sdate : '请选择开始日期'}}</view>
		</picker>
		<picker mode="date" :value="edate" @change="bindDate" data-key="edate" @cancel="cancel">
			<view class="uni-input weui-input">{{edate ? edate : '请选择结束日期'}}</view>
		</picker>
		<view class="header_bottom" @click="search">搜索</view>
	</view>
	
	<view class="top">
		<view @click="select(1)" class="header_select border_right" :class="type == 1 ? 'border-bottom' : ''">充值</view>
		<view @click="select(2)" class="header_select border_right" :class="type == 2 ? 'border-bottom' : ''">购卡</view>
		<view @click="select(3)" class="header_select border_right" :class="type == 3 ? 'border-bottom' : ''">消费</view>
	</view>
	<view class="table">
		<table border="0" width="95%" cellspacing="0" cellpadding="0">
			<tr>
				<td>客户姓名</td>
				<td>消费金额</td>
				<td>消费项目</td>
				<td>业绩分成</td>
			</tr>
			<tr v-for="(item,index) in list" :key="index">
				<td>{{item.username}}</td>
				<td>{{item.pay}}</td>
				<td>{{item.title}}</td>
				<td><image @click="jump('./share',item.id,item.pay)" src="/static/img/none_edit.jpg" alt=""></image></td>
			</tr>
		</table>
	</view>
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			//oaRole 1:店长2:员工3:商户
			type:1,
			list:[],
			page:1,
			pageShow:true,
			sdate:'',
			edate:'',
		}
	},
	onLoad:function(){
		uni.showLoading({
		    title: '加载中'  
		});
		this.getList();
	},
	methods: {
		getList:function(){
			var data = {
				type:this.type,
				oa_id:uni.getStorageSync('oa_id'),
				page:this.page,
				sdate:this.sdate,
				edate:this.edate
			}
			var that = this
			request({
				url: 'manage/center/money',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.data.last_page <= that.page){
						that.pageShow = false
					}
					if(that.page == 1){
						that.list = res.data.data.data
					}else{
						var list = that.list
						that.list = list.concat(res.data.data.data)
					}
				},
			})
		},
		select:function(key){
			this.type = key
			this.page = 1
			this.pageShow = true
			uni.showLoading()
			this.getList();
		},
		onReachBottom: function(){
			if(this.pageShow){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getList();
			}
		},
		jump:function(url,id,pay){
			uni.navigateTo({
			  url:url+'?id='+id+'&type='+this.type+'&pay='+pay
			})
		},
		bindDate:function(e){
			console.log(e)
			var value = e.detail.value
			var name = e.currentTarget.dataset.key
			this[name] = value
		},
		cancel:function(){
			uni.showLoading({
				title:'加载中'
			})
			this.sdate = ''
			this.edate = ''
			this.getList()
		},
		search:function(){
			if(!this.sdate || !this.edate){
				uni.showToast({
					title: '请选择开始日期和结束日期!!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			uni.showLoading({
				title:'加载中'
			})
			this.getList()
		}
	},
}
</script>
<style>
.header{
    width:100%;
    height:80rpx;
    line-height: 80rpx;
    text-align: center;
    background:#00b300;
    color:#fff;
}
.top{
    width:100%;
    height:80rpx;
    line-height: 80rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
	margin-top:20rpx;
}
.header_select{
    width:33%;
    text-align: center;
    border-bottom:1px solid #b3b3b3;
}
.border_right{
    border-right:1px solid #b3b3b3;
}
.border-bottom{
    border-bottom: 3px solid red;
}
.table{
	width:100%;
	padding:10rpx 20rpx 120rpx 20rpx;
}
table{
	margin-top:30rpx;
}
td{
	border:1rpx solid #C8C7CC;
	text-align: center;
	height:70rpx;
	line-height:70rpx;
}
td image{
	width:30rpx;
	height:30rpx;
}
.header1{
	width:100%;
	height:80rpx;
	display:flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
}
.header1 picker{
	width:40%;
	text-align: center;
	border:1px dashed #E5E5E5;
}
.header_bottom{
	width:18%;
	height:70rpx;
	line-height: 70rpx;
	background: #009900;
	text-align: center;
	color:#FFFFFF;
}
</style>